

struct Circle {
    x: f64, 
    y: f64,
    r: f64,
}

impl Circle {
    fn new(x:f64, y: f64, r: f64) -> Circle {
        Circle {x, y, r}
    }

    fn area(&self) -> f64 {
        std::f64::consts::PI * self.r * self.r
    }
}

struct Rect{
    w: f64,
    h: f64,
}

impl Rect {
    
    fn area(&self) -> f64 {
        self.w * self.h
    }
}


fn main() {

    let c = Circle::new(0.0, 0.0, 2.0);
    println!("半径：{}， 面积：{}", c.r, c.area());

    let rc = Rect{w: 3.0, h: 4.0};
    println!("矩形面积：{}", rc.area());

    let msg = Msg::Write(String::from("写"));
    msg.call();
}

// enum 方法
#[allow(unused)]
 enum Msg {
    Quit,
    Move{x:i32, y: i32},
    Write(String),
    ChangeColor(i32, i32, i32),
 }

 impl Msg {
    fn call(&self) {
        println!("Msg.Call()");
    }
 }